<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/hexo_blog/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/hexo_blog/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/hexo_blog/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/hexo_blog/images/logo.svg" color="#222">

<link rel="stylesheet" href="/hexo_blog/css/main.css">



<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.2/css/all.min.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.css">
  <script src="https://cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.js"></script>

<script class="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"bone-nails.gitee.io","root":"/hexo_blog/","images":"/hexo_blog/images","scheme":"Gemini","version":"8.2.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"motion":{"enable":false,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/hexo_blog/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":true,"preload":true}};
  </script>
<meta name="description" content="mysql的核心知识之事务实战什么是事务：123事务是对数据库进行读写的一个操作过程。提供从失败恢复到正常的方法，在操作异常时也能保证数据的一致性。不同程序间相互隔离互不干扰">
<meta property="og:type" content="article">
<meta property="og:title" content="mysql的核心知识之事务实战">
<meta property="og:url" content="https://bone-nails.gitee.io/2021/04/12/mysql%E7%9A%84%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86%E4%B9%8B%E4%BA%8B%E5%8A%A1%E5%AE%9E%E6%88%98/index.html">
<meta property="og:site_name" content="Carson Zhao">
<meta property="og:description" content="mysql的核心知识之事务实战什么是事务：123事务是对数据库进行读写的一个操作过程。提供从失败恢复到正常的方法，在操作异常时也能保证数据的一致性。不同程序间相互隔离互不干扰">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://zzj-1300408493.cos.ap-chengdu.myqcloud.com//pictures/image-20210416154935589.png">
<meta property="og:image" content="https://zzj-1300408493.cos.ap-chengdu.myqcloud.com//pictures/image-20210416160143086.png">
<meta property="og:image" content="https://zzj-1300408493.cos.ap-chengdu.myqcloud.com//pictures/image-20210416171928328.png">
<meta property="article:published_time" content="2021-04-12T05:26:22.000Z">
<meta property="article:modified_time" content="2021-04-19T03:58:55.469Z">
<meta property="article:author" content="Carson Zhao">
<meta property="article:tag" content="事务">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://zzj-1300408493.cos.ap-chengdu.myqcloud.com//pictures/image-20210416154935589.png">


<link rel="canonical" href="https://bone-nails.gitee.io/2021/04/12/mysql%E7%9A%84%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86%E4%B9%8B%E4%BA%8B%E5%8A%A1%E5%AE%9E%E6%88%98/">


<script class="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>
<title>mysql的核心知识之事务实战 | Carson Zhao</title>
  




  <noscript>
  <style>
  body { margin-top: 2rem; }

  .use-motion .menu-item,
  .use-motion .sidebar,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header {
    visibility: visible;
  }

  .use-motion .header,
  .use-motion .site-brand-container .toggle,
  .use-motion .footer { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle,
  .use-motion .custom-logo-image {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line {
    transform: scaleX(1);
  }

  .search-pop-overlay, .sidebar-nav { display: none; }
  .sidebar-panel { display: block; }
  </style>
</noscript>

<link rel="alternate" href="/hexo_blog/atom.xml" title="Carson Zhao" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/hexo_blog/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">Carson Zhao</h1>
      <i class="logo-line"></i>
    </a>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
        <li class="menu-item menu-item-home"><a href="/hexo_blog/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li>
        <li class="menu-item menu-item-about"><a href="/hexo_blog/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a></li>
        <li class="menu-item menu-item-tags"><a href="/hexo_blog/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a></li>
        <li class="menu-item menu-item-categories"><a href="/hexo_blog/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#mysql%E7%9A%84%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86%E4%B9%8B%E4%BA%8B%E5%8A%A1%E5%AE%9E%E6%88%98"><span class="nav-number">1.</span> <span class="nav-text">mysql的核心知识之事务实战</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BB%80%E4%B9%88%E6%98%AF%E4%BA%8B%E5%8A%A1%EF%BC%9A"><span class="nav-number">1.1.</span> <span class="nav-text">什么是事务：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BA%8B%E5%8A%A1%E7%9A%84%E7%89%B9%E6%80%A7%EF%BC%9A"><span class="nav-number">1.2.</span> <span class="nav-text">事务的特性：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BA%8B%E5%8A%A1%E7%9A%84%E5%BC%95%E6%93%8E%EF%BC%9A"><span class="nav-number">1.3.</span> <span class="nav-text">事务的引擎：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BA%8B%E5%8A%A1%E7%9A%84%E5%BC%80%E5%90%AF%E3%80%81%E6%8F%90%E4%BA%A4%E3%80%81%E5%9B%9E%E6%BB%9A%EF%BC%9A"><span class="nav-number">1.4.</span> <span class="nav-text">事务的开启、提交、回滚：</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%BC%80%E5%90%AF%E3%80%81%E5%85%B3%E9%97%ADautocommit%EF%BC%88%E4%B8%B4%E6%97%B6%EF%BC%89"><span class="nav-number">1.4.1.</span> <span class="nav-text">开启、关闭autocommit（临时）</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%B0%B8%E4%B9%85%E5%BC%80%E5%90%AFautocommit"><span class="nav-number">1.4.2.</span> <span class="nav-text">永久开启autocommit</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BF%AE%E6%94%B9%E6%95%B0%E6%8D%AE%E5%BA%93%E5%BC%95%E6%93%8E"><span class="nav-number">1.5.</span> <span class="nav-text">修改数据库引擎</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#mysql%E7%9A%84%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86%E4%B9%8B%E8%A7%86%E5%9B%BE%E5%AE%9E%E6%88%98"><span class="nav-number">2.</span> <span class="nav-text">mysql的核心知识之视图实战</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BB%80%E4%B9%88%E6%98%AF%E8%A7%86%E5%9B%BE%EF%BC%8C%E4%BD%9C%E7%94%A8%E6%98%AF%E4%BB%80%E4%B9%88%EF%BC%8C%E4%BC%98%E7%82%B9%EF%BC%9F"><span class="nav-number">2.1.</span> <span class="nav-text">什么是视图，作用是什么，优点？</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%88%9B%E5%BB%BA%E8%A7%86%E5%9B%BE"><span class="nav-number">2.2.</span> <span class="nav-text">创建视图</span></a></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Carson Zhao"
      src="/hexo_blog/images/1.png">
  <p class="site-author-name" itemprop="name">Carson Zhao</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/hexo_blog/archives">
          <span class="site-state-item-count">59</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/hexo_blog/categories/">
          
        <span class="site-state-item-count">14</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/hexo_blog/tags/">
          
        <span class="site-state-item-count">35</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="cc-license site-overview-item animated" itemprop="license">
    <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" class="cc-opacity" rel="noopener" target="_blank"><img src="/hexo_blog/images/cc-by-nc-sa.svg" alt="Creative Commons"></a>
  </div>



        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://bone-nails.gitee.io/2021/04/12/mysql%E7%9A%84%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86%E4%B9%8B%E4%BA%8B%E5%8A%A1%E5%AE%9E%E6%88%98/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/hexo_blog/images/1.png">
      <meta itemprop="name" content="Carson Zhao">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Carson Zhao">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          mysql的核心知识之事务实战
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2021-04-12 13:26:22" itemprop="dateCreated datePublished" datetime="2021-04-12T13:26:22+08:00">2021-04-12</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2021-04-19 11:58:55" itemprop="dateModified" datetime="2021-04-19T11:58:55+08:00">2021-04-19</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/hexo_blog/categories/mysql/" itemprop="url" rel="index"><span itemprop="name">mysql</span></a>
        </span>
    </span>

  
    <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span id="busuanzi_value_page_pv"></span>
    </span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>1.5k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>1 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h1 id="mysql的核心知识之事务实战"><a href="#mysql的核心知识之事务实战" class="headerlink" title="mysql的核心知识之事务实战"></a>mysql的核心知识之事务实战</h1><h2 id="什么是事务："><a href="#什么是事务：" class="headerlink" title="什么是事务："></a>什么是事务：</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">事务是对数据库进行读写的一个操作过程。</span><br><span class="line">提供从失败恢复到正常的方法，在操作异常时也能保证数据的一致性。</span><br><span class="line">不同程序间相互隔离互不干扰</span><br></pre></td></tr></table></figure>

<h2 id="事务的特性："><a href="#事务的特性：" class="headerlink" title="事务的特性："></a>事务的特性：</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">原子性：事务中的所有语句，要么都执行成功，要么都不执行</span><br><span class="line">隔离性：各事务的执行互不干扰</span><br><span class="line">一致性：数据保持逻辑上的合理</span><br><span class="line">持久性：对数据的更改是永久的（不仅仅是内存上的变化）</span><br></pre></td></tr></table></figure>

<h2 id="事务的引擎："><a href="#事务的引擎：" class="headerlink" title="事务的引擎："></a>事务的引擎：</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">innodb引擎</span><br></pre></td></tr></table></figure>

<h2 id="事务的开启、提交、回滚："><a href="#事务的开启、提交、回滚：" class="headerlink" title="事务的开启、提交、回滚："></a>事务的开启、提交、回滚：</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">5.7:begin;  其它版本：start transaction</span><br><span class="line">提交：commit;</span><br><span class="line">回滚：rollback</span><br></pre></td></tr></table></figure>

<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">创建一个账户表模拟转账</span><br><span class="line">create table account (</span><br><span class="line">                         id tinyint(5) zerofill auto_increment  not null comment &#39;id编号&#39;,</span><br><span class="line">                         name varchar(20) default null comment &#39;客户姓名&#39;,</span><br><span class="line">                         money decimal(10,2) not null comment &#39;账户金额&#39;,</span><br><span class="line">                         primary key (id)</span><br><span class="line">                         )engine&#x3D;innodb charset&#x3D;utf8;</span><br></pre></td></tr></table></figure>

<p><img src="https://zzj-1300408493.cos.ap-chengdu.myqcloud.com//pictures/image-20210416154935589.png" alt="image-20210416154935589"></p>
<p><img src="https://zzj-1300408493.cos.ap-chengdu.myqcloud.com//pictures/image-20210416160143086.png" alt="image-20210416160143086"></p>
<h3 id="开启、关闭autocommit（临时）"><a href="#开启、关闭autocommit（临时）" class="headerlink" title="开启、关闭autocommit（临时）"></a>开启、关闭autocommit（临时）</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">mysql&gt; set autocommit&#x3D;0;</span><br><span class="line">Query OK, 0 rows affected (0.00 sec)</span><br><span class="line"></span><br><span class="line">mysql&gt; show variables like &#39;autocommit&#39;;</span><br><span class="line">+---------------+-------+</span><br><span class="line">| Variable_name | Value |</span><br><span class="line">+---------------+-------+</span><br><span class="line">| autocommit    | OFF   |</span><br><span class="line">+---------------+-------+</span><br><span class="line">mysql&gt; set autocommit&#x3D;1;</span><br><span class="line">Query OK, 0 rows affected (0.00 sec)</span><br><span class="line">mysql&gt; </span><br><span class="line">mysql&gt; show variables like &#39;autocommit&#39;;</span><br><span class="line">+---------------+-------+</span><br><span class="line">| Variable_name | Value |</span><br><span class="line">+---------------+-------+</span><br><span class="line">| autocommit    | ON    |</span><br></pre></td></tr></table></figure>

<h3 id="永久开启autocommit"><a href="#永久开启autocommit" class="headerlink" title="永久开启autocommit"></a>永久开启autocommit</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">vi &#x2F;etc&#x2F;my.cnf  </span><br><span class="line">添加：autocommit&#x3D;1</span><br><span class="line">重启服务</span><br></pre></td></tr></table></figure>

<h2 id="修改数据库引擎"><a href="#修改数据库引擎" class="headerlink" title="修改数据库引擎"></a>修改数据库引擎</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">alter table account engine&#x3D;&#39;MyISAM&#39;;</span><br></pre></td></tr></table></figure>

<h1 id="mysql的核心知识之视图实战"><a href="#mysql的核心知识之视图实战" class="headerlink" title="mysql的核心知识之视图实战"></a>mysql的核心知识之视图实战</h1><h2 id="什么是视图，作用是什么，优点？"><a href="#什么是视图，作用是什么，优点？" class="headerlink" title="什么是视图，作用是什么，优点？"></a>什么是视图，作用是什么，优点？</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">视图是虚表，作为select语句保存在数据字典中</span><br><span class="line">将从基表查询的部分字段展示出来</span><br><span class="line">优点：</span><br><span class="line">	简单、安全、数据独立、不占空间（保障数据安全性、提高查询效率）</span><br><span class="line">	</span><br><span class="line">举例：当我们将公司的项目外包给其他人员时，不可能将全部数据库表交给别人，我们可以通过视图保证他人能访问被允许查询的结果集。</span><br><span class="line"></span><br><span class="line">缺点：性能差，修改有限制。</span><br></pre></td></tr></table></figure>

<h2 id="创建视图"><a href="#创建视图" class="headerlink" title="创建视图"></a>创建视图</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">创建的基本语法是：</span><br><span class="line">    create view &lt;视图名称&gt; as select 语句;</span><br><span class="line">    create view &lt;视图名称&gt; (字段) as select 语句;</span><br><span class="line">    create or replace view &lt;视图名称&gt;;</span><br><span class="line">   </span><br><span class="line">修改的语法是：</span><br><span class="line">alter view &lt;视图名称&gt; as select 语句;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">视图删除语法：</span><br><span class="line">drop view &lt;视图名称&gt; ;</span><br></pre></td></tr></table></figure>

<p><img src="https://zzj-1300408493.cos.ap-chengdu.myqcloud.com//pictures/image-20210416171928328.png" alt="image-20210416171928328"></p>

    </div>

    
    
    

    <footer class="post-footer">
          

<div class="post-copyright">
<ul>
  <li class="post-copyright-author">
      <strong>本文作者： </strong>Carson Zhao
  </li>
  <li class="post-copyright-link">
      <strong>本文链接：</strong>
      <a href="https://bone-nails.gitee.io/2021/04/12/mysql%E7%9A%84%E6%A0%B8%E5%BF%83%E7%9F%A5%E8%AF%86%E4%B9%8B%E4%BA%8B%E5%8A%A1%E5%AE%9E%E6%88%98/" title="mysql的核心知识之事务实战">https://bone-nails.gitee.io/2021/04/12/mysql的核心知识之事务实战/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>

          <div class="post-tags">
              <a href="/hexo_blog/tags/%E4%BA%8B%E5%8A%A1/" rel="tag"># 事务</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/hexo_blog/2021/04/01/Linux%E7%9F%A5%E8%AF%86%E6%95%B4%E7%90%862/" rel="prev" title="Linux知识整理2">
                  <i class="fa fa-chevron-left"></i> Linux知识整理2
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/hexo_blog/2021/04/12/mysql%E7%9A%84%E5%AD%98%E5%82%A8%E5%BC%95%E6%93%8E%E5%92%8C%E7%B4%A2%E5%BC%95/" rel="next" title="mysql的存储引擎和索引">
                  mysql的存储引擎和索引 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>







<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      const activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      const commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>
</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Carson Zhao</span>
</div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
      <span>站点总字数：</span>
    <span title="站点总字数">125k</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span>站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">1:54</span>
  </span>
</div>
<div class="busuanzi-count">
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <script size="300" alpha="0.6" zIndex="-1" src="https://cdn.jsdelivr.net/npm/ribbon.js@1.0.2/dist/ribbon.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js"></script>
<script src="/hexo_blog/js/utils.js"></script><script src="/hexo_blog/js/next-boot.js"></script>

  
<script src="/hexo_blog/js/local-search.js"></script>



<script>
if (document.querySelectorAll('.pdf-container').length) {
  NexT.utils.getScript('https://cdn.jsdelivr.net/npm/pdfobject@2.2.4/pdfobject.min.js', () => {
    document.querySelectorAll('.pdf-container').forEach(element => {
      PDFObject.embed(element.dataset.target, element, {
        pdfOpenParams: {
          navpanes : 0,
          toolbar  : 0,
          statusbar: 0,
          pagemode : 'thumbs',
          view     : 'FitH'
        },
        PDFJS_URL: '/hexo_blog/lib/pdf/web/viewer.html',
        height   : element.dataset.height
      });
    });
  }, window.PDFObject);
}
</script>


  <script>
    NProgress.configure({
      showSpinner: true
    });
    NProgress.start();
    document.addEventListener('readystatechange', () => {
      if (document.readyState === 'interactive') {
        NProgress.inc(0.8);
      }
      if (document.readyState === 'complete') {
        NProgress.done();
      }
    });
    document.addEventListener('pjax:send', () => {
      NProgress.start();
    });
    document.addEventListener('pjax:success', () => {
      NProgress.done();
    });
  </script>

  
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>





<script src="/hexo_blog/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginModelPath":"assets/","model":{"jsonPath":"/hexo_blog/live2dw/assets/hijiki.model.json"},"display":{"position":"right","width":200,"height":400},"mobile":{"show":true},"log":false,"pluginJsPath":"lib/","pluginRootPath":"live2dw/","tagMode":false});</script></body>
</html>
